<!--
  表单内的表格组件
  @author YangMiao 1939724848@qq.com
  @date 2022/3/29 14:27
  @version 1.0.0
-->
<template>
  <el-col :span="24">
    <div class="area-header" style="margin-top: 20px;">
      <span class="area-header-title">{{ $t(title) }}</span>
    </div>
    <el-table :data="dataList" border class="nowrapTable formTable">
      <el-table-column type="index" label="序号" />
      <slot />
      <el-table-column :label="$t('操作')" width="60px">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="hasPermiArr"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="clickDelData(scope.$index, scope.row)"
          />
        </template>
      </el-table-column>
    </el-table>
    <div class="tol">
      <el-button type="primary" icon="el-icon-plus" size="mini" @click="clickAddData">{{ $t("添加") }}</el-button>
    </div>
  </el-col>
</template>

<script>
export default {
  name: 'FormInnerTable',
  props: {
    /**
     * 标题
     * @author YangMiao 1939724848@qq.com
     * @date   2022/3/29 14:33
     */
    title: {
      type: String,
      default: ''
    },
    /**
     * 表格集合
     * @author YangMiao 1939724848@qq.com
     * @date   2022/3/29 14:33
     */
    dataList: {
      type: Array,
      default: () => []
    },
    /**
     * 点击添加时 新增到集合的对象
     * @author YangMiao 1939724848@qq.com
     * @date   2022/3/29 14:32
     */
    initData: {
      type: Object,
      default: () => {}
    },
    /**
     * 操作权限
     * @author YangMiao 1939724848@qq.com
     * @date   2022/7/26 16:38
     */
    hasPermiArr: {
      type: Array,
      default: () => ['fund:expense:remove']
    }
  },
  methods: {
    clickDelData(index) {
      this.dataList.splice(index, 1)
    },
    clickAddData() {
      this.dataList.push(Object.assign({}, this.initData))
    }
  }
}
</script>

<style scoped>

</style>
